<?php
	class Board extends MY_Controller {
	//add variables here
	var $board;

	//required constructor
	public function __construct()
	{
		parent::__construct();
		
		$this->load->model('User_model', 'user');
		$this->load->model('Board_model', 'board');
		$this->load->model('Thread_model', 'thread');
		$this->load->model('Message_model', 'message');
	}
	
	public function _remap($method)
	{
		$this->board = $this->board->get_board(intval($method));
		$this->index();
	}
	
	public function index()
	{
		$this->data['board'] = $this->board;
		
		$threads = $this->thread->get_board_threads( $this->board['BoardID'] );
		$this->populate_message_count($threads);
		$this->data['threads'] = $threads;
	
		$this->data['main_content_view'] = $this->load->view('board_view', $this->data, true);
		$this->load->view('default', $this->data);
	}
	
	private function populate_message_count( &$threads )
	{
		foreach( $threads as &$thread )
		{
			$thread['count'] = count($this->message->get_thread_messages($thread['ThreadID']));
		}
	}
}
?>